package com.ruoyi.app.controller;

import com.ruoyi.app.domain.Card;
import com.ruoyi.app.domain.Department;
import com.ruoyi.app.domain.Hospital;
import com.ruoyi.app.domain.InpatientRegister;
import com.ruoyi.app.domain.vo.InpatientRegisterVo;
import com.ruoyi.app.service.*;
import com.ruoyi.app.util.Result;
import com.ruoyi.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("inpatientRegister")
@RestController
public class InpatientRegisterConreoller {
    @Autowired
    InpatientRegisterService inpatientRegisterService;
    @Autowired
    CardService cardService;
    @Autowired
    DepartmentService departmentService;
    @Autowired
    HospitalService hospitalService;
    @Autowired
    RedisService redisService;

    @RequestMapping("getlist")
    public Result getList(Integer userId){
        List<InpatientRegister> list = inpatientRegisterService.getList(userId);
        for (InpatientRegister inpatientRegister : list) {
            Card card = cardService.getByName(inpatientRegister.getPatient().getIdType());
            inpatientRegister.getPatient().setIdTypeName(card.getCardName());

            Department  department = departmentService.getById(inpatientRegister.getPatient().getDepartmentId());
            inpatientRegister.getPatient().setDepartmentIName(department.getName());

        }
        return Result.ok(list);
    }

    @RequestMapping("getListBy")
    public Result getListBy(String inpatientNo){
        List<InpatientRegister> list = inpatientRegisterService.getListBy(inpatientNo);
        for (InpatientRegister inpatientRegister : list) {
            Card card = cardService.getByName(inpatientRegister.getPatient().getIdType());
            inpatientRegister.getPatient().setIdTypeName(card.getCardName());

            Department  department = departmentService.getById(inpatientRegister.getPatient().getDepartmentId());
            inpatientRegister.getPatient().setDepartmentIName(department.getName());

            Hospital  hospital = hospitalService.getById(inpatientRegister.getPatient().getHospitalAreaId());
            inpatientRegister.getPatient().setHospitalName(hospital.getName());

        }
        return Result.ok(list);
    }


    // 根据住院号查询
    @RequestMapping("select")
    public Result select(String inpatientNo){
        InpatientRegisterVo vo = inpatientRegisterService.select(inpatientNo);
//        System.err.println("住院人为"+vo);
        return Result.ok(vo);
    }
}
